<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: guzhe
  Date: 2020/12/8
  Time: 15:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
//获取用户名和密码
    String userName=request.getParameter("username");
    String password=request.getParameter("password");
    //连接数据库
    /*
    * Connection对象 建立连接  用户不能通过new创建
    * Statement对象  客户端和服务器端交互
    * ResultSet对象 用于返回结果
    *
    * */
    //1. register driver
Class.forName("com.mysql.jdbc.Driver");
//2.获取connection 对象
    //三个参数
    //url
    //uesename
    //password
    String url="jdbc:mysql://localhost:3306/software18?serverTimezone=Asia/Shanghai";
    String dbName="root";
    String dbPassword="489436gzl";
    Connection conn= DriverManager.getConnection(url,dbName,dbPassword);
    //3.获取什么样数据？编写sql
    String sql="select * from tb1_user";
    String sql1="select *from tb1_user where username=? and password=?";
    PreparedStatement preparedStatement = conn.prepareStatement(sql1);
    //4.创建statement对象
    preparedStatement.setString(1,userName);
    preparedStatement.setString(2,password);
   // Statement statement=conn.createStatement();
    //5.  execute query ,return resultset object
    ResultSet resultSet=preparedStatement.executeQuery(sql1);
    //6.遍历结果集
    if (resultSet.next()){
       // out.print(resultSet.getString(1)+","+resultSet.getString(2)+","+resultSet.getString(3)+"<br>");
       out.print("密码正确");
    }else{
        out.print("密码错误");
    }
%>